home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / ibink10.arc / IBINK.C < prev    next >
C/C++ Source or Header  |  1991-03-09  |  6KB  |  204 lines

  1. /* IBINK.C - Author: David Bennett (1:280/307) - Date: 3/7/91 - Version: 1.0
  2.  *
  3.  * Compiled Using Borland C++ (Should compile fine under Turbo C 2.0)
  4.  *
  5.  * Convert Arcmail to Binkley type .FLO file entries.
  6.  *
  7.  * .MSG requirements
  8.  *
  9.  *   .MSG must be addressed to "ARCMail"
  10.  *   attached flag must be true
  11.  *   local flag must be true
  12.  *   if hold is set the extension becomes .HLO (precedence over crash)
  13.  *   if crash is set the extension becomes .CLO (precedence over direct)
  14.  *   if direct is set the extention becomes .DLO
  15.  *   if killsent is set then .MSG is unlinked after .?LO is updated
  16.  *
  17.  *  Note: In outbound .?LO files a '^' preceding a filename deletes that
  18.  *        file after sending.  A '#' preceding the name truncates the name
  19.  *        to 0.  I am using '#' here in hopes that IMAIL will check and
  20.  *        not create duplicate outbound archive names.
  21.  *
  22.  * Ideas for improvments & enhancments:
  23.  *
  24.  * - Move this code into Binkley.  Then Binkley could support ARCMail
  25.  *   attaches directly.
  26.  *
  27.  * - Add support for BINKLEY.CFG so you don't have to specify the
  28.  *   directories on the command line.
  29.  *
  30.  * - Add logging.
  31.  */
  32.  
  33. #include <dir.h>
  34. #include <dos.h>
  35. #include <stdio.h>
  36. #include <string.h>
  37.  
  38. #include "fidoadr.h"
  39. #include "ibink.h"
  40.  
  41. char *title="\nIBINK - Author: David Bennett (1:280/307) - Date: 3/7/91 - Version: 1.0\n\n";
  42. char *usage= \
  43.     "  Convert's IMAIL generated ARCMail attaches to Binkley .?LO\n" \
  44.     "\n" \
  45.     "Usage: IBINK <hudson netmail dir> <binkley base outbound dir>\n" \
  46.     "\n" \
  47.     "Where:\n" \
  48.     "\n" \
  49.     "     <hudson netmail dir> - Is the directory that 'IMAIL SCAN'\n" \
  50.     "     creates the ARCMail attaches (###.MSG files) in.\n" \
  51.     "\n" \
  52.     "     <binkley base outbound dir> - Is the base (zone 1) outbound\n" \
  53.     "     specification for BinkleyTerm.\n" \
  54.     "\n" \
  55.     "- Multi-Zone attaches are supported.  OUTBOUND.### zone directories\n" \
  56.     "  are created if they don't exist.\n" \
  57.     "\n" \
  58.     "- It is recommended that you supply a different directory for IMAIL's\n" \
  59.     "  outbound specification than your Binkley outbound directory.\n";
  60.  
  61. char inspec[MAXPATH];            /* Input directory spec (netmail) */
  62. char inpath[MAXPATH];           /* Input path (netmail) */
  63. char outpath[MAXPATH];          /* Output base path (bink outbound) */
  64. char inname[MAXPATH];           /* Input filename (netmail .MSG) */
  65. char outname[MAXPATH];          /* Output filename (outbound .?LO) */
  66. char tmpname[MAXFILE];          /* Temporary name to check .MSG file */
  67. char tmpstr[MAXPATH];           /* Temporary throw away area for fn_split() */
  68. char hexstr[MAXFILE];           /* Hex string for outbound dir filenames */
  69. char outext[MAXEXT];                /* Output extention (.FLO .CLO .HLO) */
  70. FIDOHEADER fidohdr;             /* .MSG header */
  71. FIDOADR destadr=DEF_FIDOADR;    /* Destination address */
  72. char msgtxt[0x4000];            /* 16k for message text,  more than enough */
  73.  
  74. void main(int argc, char **argv)
  75. {
  76.     int i, test;
  77.     FILE *infile, *outfile;
  78.     char *p;
  79.     struct ffblk fb;
  80.  
  81.     fputs(title, stderr);
  82.     if (argc != 3) {
  83.         fputs(usage, stderr);
  84.         exit(1);
  85.     }
  86.  
  87.     /*
  88.      * Add '\' to end of the netmail path if not there.
  89.      */
  90.     strcpy(inpath, argv[1]);
  91.     if (inpath[strlen(inpath)-1] != '\\') strcat(inpath, "\\");
  92.     strcpy(inspec, inpath);
  93.     strcat(inspec, "*.MSG");
  94.  
  95.     /*
  96.      * Remove the '\' from the end of the outbound path if it is there
  97.      * so the .zzz zone extension can be added if necessary.
  98.      */
  99.     strcpy(outpath, argv[2]);
  100.     p = &(outpath[strlen(outpath)-1]);
  101.     if (*p == '\\') *p = '\0';
  102.  
  103.     if (!findfirst(inspec, &fb, 0)) do {
  104.  
  105.         strcpy(inname, inpath);
  106.         strcat(inname, fb.ff_name);
  107.  
  108.         /*
  109.          * Check for valid filename and open the .MSG file
  110.          */
  111.         fnsplit(inname, tmpstr, tmpstr, tmpname, tmpstr);
  112.         if (atoi(tmpname)) infile = fopen(inname, "rb");
  113.         else infile = NULL;
  114.  
  115.         if (infile) {
  116.  
  117.             /*
  118.              * Read the Fido header
  119.              */
  120.             if (fread(&fidohdr, sizeof(FIDOHEADER), 1, infile) == 1) {
  121.  
  122.                 test = stricmp(fidohdr.to, "arcmail");
  123.                 test = (test && fidohdr.attr.attached && fidohdr.attr.local);
  124.                 if (test) {
  125.  
  126.                     /*
  127.                      * Calculate file attach extension.
  128.                      */
  129.                     if (fidohdr.attr.hold) strcpy(outext, ".HLO");
  130.                     else if (fidohdr.attr.crash) strcpy(outext, ".CLO");
  131.                     else if (fidohdr.attr.direct) strcpy(outext, ".DLO");
  132.                     else strcpy(outext, ".FLO");
  133.  
  134.                     /*
  135.                      * Read message text
  136.                      */
  137.                     fread(msgtxt, sizeof(msgtxt), 1, infile);
  138.  
  139.                     /*
  140.                      * Check for Multi-zone address
  141.                      */
  142.                     memset(&destadr, 0, sizeof(FIDOADR));
  143.                     p = strstr(msgtxt, "\x01INTL");
  144.                     if (p) {
  145.                         p = strchr(p, ' ');
  146.                         strtok(++p, " ");
  147.                         fidoadr_split(p, &destadr);
  148.                     }
  149.                     else {
  150.                         destadr.net = fidohdr.dest_net;
  151.                         destadr.node = fidohdr.dest;
  152.                     }
  153.  
  154.                     /*
  155.                      * Status display
  156.                      */
  157.                     fidoadr_merge(tmpstr, &destadr);
  158.                     printf("ARCMail attach to (%s)\t -> ", tmpstr);
  159.  
  160.                     /*
  161.                      * Create/Update correct outbound directory
  162.                      * (C:\BT\OUTBOUND.zzz)
  163.                      */
  164.                     strcpy(outname, outpath);
  165.                     if (destadr.zone > 1) {
  166.                         sprintf(hexstr, "\.%03X", destadr.zone);
  167.                         strcat(outname, hexstr);
  168.                     }
  169.  
  170.                     /*
  171.                      * Make outbound directory or fail harmlessly.
  172.                      */
  173.                     mkdir(outname);
  174.  
  175.                     /*
  176.                      * add ?LO file name.
  177.                      */
  178.                     strcat(outname, "\\");
  179.                     hexadr_merge(hexstr, destadr.net, destadr.node);
  180.                     strcat(outname, hexstr);
  181.                     strcat(outname, outext);
  182.  
  183.                     /*
  184.                      * Status display
  185.                      */
  186.                     printf("%s\n", outname);
  187.  
  188.                     /*
  189.                      * Create/Append the file attach.
  190.                      */
  191.                     outfile = fopen(outname, "at");
  192.                     if (outfile) {
  193.                         fprintf(outfile, "#%s\n", strupr(fidohdr.subj));
  194.                         fclose(outfile);
  195.                     }
  196.                 }
  197.                 fclose(infile);
  198.                 if (fidohdr.attr.killsent) unlink(inname);
  199.             }
  200.         }
  201.     } while (!findnext(&fb));
  202. }
  203.  
  204.